/**
 * Created by John on 2016/7/11.
 */
var blog = {
    word: 'blog',
    first: 'b',
    last: 'g',
    size: 4,
    letters: ['b', 'l', 'o', 'g'],
    stats: {vowels: 1, consonants: 3},
    charsets: [
        {
            type: 'consonants',
            chars: ['b', 'l', 'g']
        },
        {
            type: 'vowels',
            chars: ['o']
        }
    ],
    category: 'New'
};

var mongo = new Mongo("localhost");
var wordsDB = mongo.getDB("BeginningMongoDB");
wordsColl = wordsDB.getCollection("word_stats");

wordsDB.runCommand({getLastError: 1, w: 1, j: true, wtimeout: 1000});

var blue = {category: 'blue'};
var projection = {word: 1, category: 1};
var cursor = wordsColl.find(blue, projection);
print('Before Existing Save:');
printjson(cursor.toArray());

var word = wordsColl.findOne({word: 'the'});
word.category = 'blue';
wordsColl.save(word);
word = wordsColl.findOne({word: 'be'});
word.category = 'blue';
wordsColl.save(word);
cursor = wordsColl.find(blue, projection);
print('After Existing Save:');
printjson(cursor.toArray());

word = wordsColl.findOne({word: 'blog'});
print('Before New Document Save:');
printjson(word);
wordsColl.save(blog);
word = wordsColl.findOne({word: 'blog'}, projection);
print('After New Document Save:');
printjson(word);